package com.sso.shiro;

import com.sso.common.enums.SysResourceEnum;
import com.sso.entity.view.SysMenuResourceView;
import com.sso.manager.SysMenuResourceViewManager;
import com.tools.util.StrUtils;
import org.apache.shiro.config.Ini;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Admin on 2016/1/26.
 */
public class DefaultChainDefinitionsFactoryBean implements FactoryBean<Ini.Section> {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private SysMenuResourceViewManager menuResourceViewManager;
    private String filterChainDefinitions = "/static/**=anon";

    @Override
    public Ini.Section getObject() throws Exception {
        //通过传递内存地址的形式来装配url权限
        Ini ini = new Ini();
        ini.load(filterChainDefinitions);
        Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
        section.put("/js/**", "anon");
        section.put("/css/**", "anon");
        section.put("/images/**", "anon");
        section.put("/lib/**", "anon");
        //查询菜单与资源绑定视图
        menuResourceViewManager.getLoadSection(section);
        section.put("/**", "authc");
        return section;
    }
    @Override
    public Class<?> getObjectType() {
        // TODO Auto-generated method stub
        return this.getClass();
    }
    @Override
    public boolean isSingleton() {
        // TODO Auto-generated method stub
        return false;
    }
}
